package lines.gameengine.util;

import lines.gameengine.FieldPoint;
import lines.gameengine.IField;

import java.util.*;

/**
 * @author vpotapenko
 */
public class DefaultCellsChooser implements ICellsChooser {

    private final Random random = new Random();

    @Override
    public Collection<FieldPoint> chooseEmptyCellsForNextStep(IField field) {
        List<FieldPoint> emptyPoints = LinesEngineUtils.getEmptyCells(field);
        final int ballsPerStep = field.getContext().getParameters().getBallsPerStep();
        if (emptyPoints.size() <= ballsPerStep) return emptyPoints;

        Collection<FieldPoint> points = new HashSet<FieldPoint>();
        for (int i = 0; i < ballsPerStep; i++) {
            int index = random.nextInt(emptyPoints.size());
            points.add(emptyPoints.remove(index));
        }
        return points;
    }
}
